package stock;

import java.util.List;

public class Test6 {
	public static float calculateDifferenceRatio(List<Float> numbers) {
		if (numbers == null || numbers.isEmpty()) {
			throw new IllegalArgumentException("List<Float> should not be null or empty.");
		}

		float firstNumber = numbers.get(0);
		float minNumber = numbers.get(0); // 初始化为第一个数

		for (float number : numbers) {
			if (number < minNumber) {
				minNumber = number;
			}
		}

		// float difference = Math.abs(firstNumber - minNumber);
		float ratio = ((firstNumber - minNumber) / firstNumber) * 100;

		return ratio;
	}

	public static void main(String[] args) {
		List<Float> numbers = List.of(5.0f, 3.0f, 8.0f, 2.0f, 1.0f);
		float differenceRatio = calculateDifferenceRatio(numbers);
		System.out.println("第一个数与当前列表最小值的差距比例为: " + differenceRatio + "%");
	}
}
